<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>

<form:form commandName="excelData" cssClass="form-horizontal" role="form">
	<input type="hidden" name="sysId" id="excel_id">
	<div class="panel panel-default">
			<%--承办人--%>
		<input type="hidden" id="chengbanrenshuju"  value="${excelData.cell6}" />
			<%--抄送领导--%>
		<input type="hidden" id="caosongshuju"  value="${excelData.cell8}" />
			<%--牵头单位--%>
		<input type="hidden" id="qiantoushuju"     value="${excelData.cell6}" />
			<%--协办单位--%>
		<input type="hidden"id="xiebanshuju"     value="${excelData.cell7}" />
		<input type="hidden" id="inside-batchNum"     value="${excelData.batchNum}" />
		<div class="panel-body">
			<div class="form-group">

				<label class="col-sm-2 control-label no-padding-right" for="excelData"><font color="red">校验信息</font></label>
				<div class="col-sm-10">
					<textarea rows="3" cols="70" class="chance_remarks"  readonly>${excelData.remarks}"</textarea>
				</div>
			</div>
			<div class="form-group">

				<label class="col-sm-2 control-label no-padding-right" for="excelData">事项<font color="red">*</font></label>
				<div class="col-sm-10">
					<textarea rows="5" cols="70" name="cell0" class="chance1_1_17">${excelData.cell0}"</textarea>
				</div>
			</div>
				<%--            <div class="form-group">--%>
				<%--				<label class="col-sm-2 control-label no-padding-right" for="excelData">抄送领导<font color="red">*</font></label>--%>
				<%--				<div class="col-sm-8" id="caosonglingdaoid">--%>
				<%--						&lt;%&ndash;					<input type="number" name="ruleRatio"  min="0" max="100" placeholder="占比"  value="${excelData.cell5}" class="form-control" required >&ndash;%&gt;--%>
				<%--				</div>--%>
				<%--			</div>--%>
				<%--			<div class="form-group">--%>

				<%--				<label class="col-sm-2 control-label no-padding-right" for="excelData">牵头单位<font color="red">*</font></label>--%>
				<%--				<div class="col-sm-8" id="qiantoudanweiid">--%>
				<%--&lt;%&ndash;					<input type="text"  name="ruleName"   value="${excelData.cell1}" min="0" max="100" placeholder="评价" class="form-control" required >&ndash;%&gt;--%>
				<%--				</div>--%>

				<%--			</div>--%>
				<%--			<div class="form-group">--%>
				<%--				<label class="col-sm-2 control-label no-padding-right" for="excelData">协办单位<font color="red">*</font></label>--%>
				<%--				<div class="col-sm-8" id="xiebandanweiid">--%>
				<%--						&lt;%&ndash;					<input type="text" name="ruleRatio"  placeholder="占比"  value="${excelData.cell2}" class="form-control" required >&ndash;%&gt;--%>
				<%--				</div>--%>
				<%--			</div>--%>
			<div class="form-group">
				<label class="col-sm-2 control-label no-padding-right" for="excelData">承办人<font color="red">*</font></label>
				<div class="col-sm-8" id="chengbanrenid">
						<%--					<input type="text" name="ruleRatio"  placeholder="占比"  value="${excelData.cell2}" class="form-control" required >--%>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label no-padding-right" for="evalRules">周期类型<font color="red">*</font></label>
				<div class="col-sm-3">
					<input type="hidden" id="cell3Id"   value="${excelData.cell3}" placeholder="评价" class="form-control" required >
					<select name="cell3" id="theruleName" onchange="chanceSelect(this.options[this.options.selectedIndex].value,'')">
						<option value="多时限">多时限</option>
						<option value="单时限">单时限</option>
						<option value="天">天</option>
						<option value="周">周</option>
						<option value="月">月</option>
						<option value="季度">季度</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label no-padding-right" for="evalRules">时限<font color="red">*</font></label>
				<div class="col-sm-5" id="shijianxuanxiang">
					<input type="text" name="cell4"   value="${excelData.cell4}" class="form-control chance2_1_17" required >
				</div>
			</div>
		</div>
	</div>
</form:form>
<script>
	var theid = ""
	var idArr = []
	$.ajax({
		url:'/excel/data/getFailList?batchNum='+$("#inside-batchNum").val(),
		dataType:'json',
		type:'get',
		contentType:'application/json',
		success:function (res) {
			idArr = res.data.failList
			var danyan = setInterval(function(){
				if(theid>idArr.length-1){
					alert("已经是最后一条！")
					clearInterval(danyan)
				}else if(theid != sessionStorage.getItem("nbthefailList")){
					theid = sessionStorage.getItem("nbthefailList")
					var params = {
						"sysId":idArr[theid]
					}
					console.log(params)
					$.ajax({
						url:'/excel/data/getById',
						dataType:'json',
						type:'POST',
						data:JSON.stringify(params),
						contentType:'application/json',
						success:function (res) {
							$(".chance_remarks").val(res.data.remarks)
							$(".chance1_1_17").val(res.data.cell0)
							// $(".chance2_1_17").val(res.data.cell4)
							$("#chengbanrenshuju").val(res.data.cell6)
							$("#cell3Id").val(res.data.cell3)
							$("#excel_id").val(res.data.sysId)
							nbgetTheInfo()
							chanceSelect(res.data.cell3,res.data.cell4)
						}
					});
				}
			},1000)
		}
	});
</script>
<script>
	function nbgetTheInfo(){
		$.ajax({
			url:"/insideDept/getDeptUsers",
			async:false,
			success:function (data) {
				console.log(data)
				var  chengbanren = ""
				for (var i = 0; i<data.length;i++ ){
					chengbanren += " <option value=\""+ data[i].userId +"\">"+data[i].name +"</option>";
				}
				var  chengbanrenhtml =   "<div class=\"col-sm-12\">\n" +
						"                <select multiple=\"true\" id=\"e1\" name=\"\" class=\"chengbanrentanchuang\" onchange=\"chengbanrenCC(this)\">"+ chengbanren +"</select>\n" +
						"                    <input type=\"hidden\" value=\"\" name=\"cell6\">\n" +
						"                </div>\n" +
						"           </div>"
				$("#chengbanrenid").html(chengbanrenhtml)
				$(".chengbanrentanchuang").select2({
					placeholder: "请输入或点击选择承办人",
					width: "100%",
					closeOnSelect: false,
					allowClear: true,
				});
				var chengbanrenshuju = document.getElementById("chengbanrenshuju").value.split(",")
				$(".chengbanrentanchuang").val(chengbanrenshuju).trigger('change')
			}
		})
		var theruleNames = document.getElementById("theruleName").children
		var cell3Id = document.getElementById("cell3Id").value
		for (let i = 0; i < theruleNames.length; i++) {
			if(theruleNames[i].value == cell3Id){
				theruleNames[i].selected = "selected"
			}
		}
	}
	// /insideDept/getDeptUsers
	// $(document).ready(function (){
	// 	$.ajax({
	// 		type:"POST",
	// 		data:{deptId:""},
	// 		url:"/taskMain/cbDeptList/",
	// 		async:false,
	// 		success:function (data) {
	// 			danwei = "";
	// 			danweiArr = [];
	// 			for (var i = 0; i<data.length; i++){
	// 				danwei += " <option value=\""+ data[i].sysId +"\">"+data[i].deptName +"</option>";
	// 				danweiArr.push({danweiSysId:data[i].sysId,danweiName:data[i].deptName});
	// 			}
	// 			var htmlqiantou = "<div class=\"col-sm-12\">\n" +
	// 					"                <select multiple=\"true\"  class=\"qiantoutanchaung\" onchange='qiantouMonitor(this)'> "+ danwei + "</select>\n" +
	// 					"               <input type='hidden' value='' name=\"cell6\">\n" +
	// 					"            </div>\n"
	// 			$("#qiantoudanweiid").html(htmlqiantou)
	// 			var htmlxieban= "<div class=\"col-sm-12\">\n" +
	// 					"                <select multiple=\"true\"  class=\"xiebantanchaung\" onchange='xiebanMonitor2(this)'> "+ danwei + "</select>\n" +
	// 					"               <input type='hidden' value='' name=\"cell7\">\n" +
	// 					"            </div>\n"
	// 			// cell5
	// 			$("#xiebandanweiid").html(htmlxieban)
	// 			$(".qiantoutanchaung").select2({
	// 				placeholder: "请输入或点击选择牵头单位",
	// 				width: "100%",
	// 				closeOnSelect: false,
	// 				allowClear: true,
	// 			});
	// 			$(".xiebantanchaung").select2({
	// 				placeholder: "请输入或点击选择协办单位",
	// 				width: "100%",
	// 				closeOnSelect: false,
	// 				allowClear: true,
	// 			});
	// 			var qiantoushuju = document.getElementById("qiantoushuju").value.split(",")
	// 			var xiebanshuju = document.getElementById("xiebanshuju").value.split(",")
	// 			$(".qiantoutanchaung").val(qiantoushuju).trigger('change')
	// 			$(".xiebantanchaung").val(xiebanshuju).trigger('change')
	// 		}
	// 	})
	// 	$.ajax({
	// 		url:"/taskMain/leaderList/",
	// 		async:false,
	// 		success:function (data) {
	// 			var  xianlingdao = ""
	// 			for (var i = 0; i<data.length;i++ ){
	// 				xianlingdao += " <option value=\""+ data[i].sysId +"\">"+data[i].name +"</option>";
	// 			}
	// 			var  caosonghtml =   "            <div class=\"col-sm-12\">\n" +
	// 					"                <select multiple=\"true\" id=\"e1\" name=\"\" class=\"caosongtanchuang\" onchange=\"caosongCC(this)\">"+ xianlingdao +"</select>\n" +
	// 					"                    <input type=\"hidden\" value=\"\" name=\"cell8\">\n" +
	// 					"                </div>\n" +
	// 					"           </div>"
	// 			$("#caosonglingdaoid").html(caosonghtml)
	// 			$(".caosongtanchuang").select2({
	// 				placeholder: "请输入或点击选择抄送领导",
	// 				width: "100%",
	// 				closeOnSelect: false,
	// 				allowClear: true,
	// 			});
	// 			var caosongshuju = document.getElementById("caosongshuju").value.split(",")
	// 			$(".caosongtanchuang").val(caosongshuju).trigger('change')
	// 		}
	// 	})
	// })
	function caosongCC(data) {
		console.log(data)
		$(data).siblings("input").val($(data).val().join(","));
	}
	function qiantouMonitor(data)  {
		var $data = $(data).val();//获取全部select的值
		console.log($data)
		//临时数组存放
		var tempArray1 = []; //临时数组1
		var tempArray2 = []; //临时数组2
		for (var i = 0; i < $data.length; i++) {
			tempArray1[$data[i]] = true; //将数array2 中的元素值作为tempArray1 中的键，值为true；
		}
		for (var i = 0; i < danweiArr.length; i++) {
			if (!tempArray1[danweiArr[i].danweiSysId]) {
				tempArray2.push(danweiArr[i]); //过滤array1 中与array2 不相同的元素；
			}
		}
		var xieban;
		for (var i = 0; i<tempArray2.length; i++){
			xieban +=  " <option value=\""+ tempArray2[i].danweiSysId +"\">"+tempArray2[i].danweiName +"</option>"
		}
		$(data).parent().parent().siblings().find("select.xieban").html(xieban);
		$(data).siblings("input").val($(data).val().join(","));
	}
	function xiebanMonitor2(data)  {
		var $data = $(data).val();//获取全部select的值
		//临时数组存放
		var tempArray1 = []; //临时数组1
		var tempArray2 = []; //临时数组2
		for (var i = 0; i < $data.length; i++) {
			tempArray1[$data[i]] = true; //将数array2 中的元素值作为tempArray1 中的键，值为true；
		}
		for (var i = 0; i < danweiArr.length; i++) {
			if (!tempArray1[danweiArr[i].danweiSysId]) {
				tempArray2.push(danweiArr[i]); //过滤array1 中与array2 不相同的元素；
			}
		}
		var xieban;
		for (var i = 0; i<tempArray2.length; i++){
			xieban +=  " <option value=\""+ tempArray2[i].danweiSysId +"\">"+tempArray2[i].danweiName +"</option>"
		}
		$(data).parent().parent().siblings().find("select.xieban").html(xieban);
		$(data).siblings("input").val($(data).val().join(","));
	}
	function chengbanrenCC(data) {
		console.log(data)
		$(data).siblings("input").val($(data).val().join(","));
	}
</script>
<script>
	function chanceSelect(data,thevalue){
		var xuanxianghtml = ""
		if(data == "多时限"){
			var valuehtml = ""
			if(thevalue != null && thevalue!= undefined && thevalue!=""){
				var valueArr = thevalue.split(",")
				for (var i = 0; i < valueArr.length; i++) {
					valuehtml +=	"    <div class=\"col-sm-8\">\n" +
							"        <input type=\"text\" placeholder=\"年-月-日\"  value = "+ valueArr[i] + "  onblur=\"addTimeBtnData()\"     class=\"form-control Zdate_picker danyan\" readonly>\n" +
							"    </div>\n"
				}
			}else{
				valuehtml =	"    <div class=\"col-sm-8\">\n" +
						"        <input type=\"text\" placeholder=\"年-月-日\" onblur=\"addTimeBtnData()\"     class=\"form-control Zdate_picker danyan\" readonly>\n" +
						"    </div>\n"
			}
			xuanxianghtml = "<div class='form-group'>" +
					valuehtml +
					"    <div class=\"col-sm-1 addTime\">\n" +
					"        <input type=\"button\" class=\"btn btn-sm btn-success\" onclick='addTimeBtn(this)' value=\"添加时限\">\n" +
					"        <input id=\"cell4Id\" type=\"hidden\" name=\"cell4\" class=\"form-control\" >\n" +
					"    </div>\n" +
					"    </div>"
		}
		if(data == "单时限"){
			if(thevalue==""){
				xuanxianghtml = "<div class='form-group'>" +
						"    <div class=\"col-sm-8\">\n" +
						"        <input type=\"text\"  value = \"\"    class=\"form-control Zdate_picker transform\" name=\"cell4\" readonly>\n" +
						"    </div>\n" +
						"    </div>"
			}else{
				xuanxianghtml = "<div class='form-group'>" +
						"    <div class=\"col-sm-8\">\n" +
						"        <input type=\"text\"  value = "+ thevalue + "    class=\"form-control Zdate_picker transform\" name=\"cell4\" readonly>\n" +
						"    </div>\n" +
						"    </div>"
			}
		}
		if(data == "天"){
			if(thevalue==""){
				xuanxianghtml = "<input type=\"number\"  value = \"\"    class=\"form-control\" min='0' name=\"cell4\" placeholder=\"请输入天数\">"
			}else{
				xuanxianghtml = "<input type=\"number\"  value = "+ thevalue + "    class=\"form-control\" min='0' name=\"cell4\" placeholder=\"请输入天数\">"
			}
		}
		if(data == "周"){
			if(thevalue==""){
				xuanxianghtml  = "      <select name=\"cell4\"  value = \"\"    class=\"form-control\">\n" +
						"            <option value=\"1\">星期一</option>\n" +
						"            <option value=\"2\">星期二</option>\n" +
						"            <option value=\"3\">星期三</option>\n" +
						"            <option value=\"4\">星期四</option>\n" +
						"            <option value=\"5\">星期五</option>\n" +
						"            <option value=\"6\">星期六</option>\n" +
						"            <option value=\"7\">星期日</option>\n" +
						"        </select>"
			}else{
				xuanxianghtml  = "      <select name=\"cell4\"  value = "+ thevalue + "    class=\"form-control\">\n" +
						"            <option value=\"1\">星期一</option>\n" +
						"            <option value=\"2\">星期二</option>\n" +
						"            <option value=\"3\">星期三</option>\n" +
						"            <option value=\"4\">星期四</option>\n" +
						"            <option value=\"5\">星期五</option>\n" +
						"            <option value=\"6\">星期六</option>\n" +
						"            <option value=\"7\">星期日</option>\n" +
						"        </select>"
			}
		}
		if(data == "月"){
			if(thevalue==""){
				xuanxianghtml  = "<input type=\"text\"   value = \"\"    readonly lay-verify=\"date\" placeholder=\"日\" name=\"cell4\" autocomplete=\"off\" class=\"layui-input date_picker form-control\">\n"
			}else{
				xuanxianghtml  = "<input type=\"text\"   value = "+ thevalue + "    readonly lay-verify=\"date\" placeholder=\"日\" name=\"cell4\" autocomplete=\"off\" class=\"layui-input date_picker form-control\">\n"
			}
		}
		if(data == "季度"){
			if(thevalue==""){
				xuanxianghtml  = "<input type=\"text\"   value = \"\"   readonly lay-verify=\"date\" placeholder=\"年-月-日\" name=\"cell4\" autocomplete=\"off\" class=\"layui-input form-control date_picker\">\n"
			}else{
				xuanxianghtml  = "<input type=\"text\"   value = "+ thevalue + "   readonly lay-verify=\"date\" placeholder=\"年-月-日\" name=\"cell4\" autocomplete=\"off\" class=\"layui-input form-control date_picker\">\n"
			}
		}
		$("#shijianxuanxiang").html(xuanxianghtml)
	}
	function addTimeBtn(e) {
		var html = " <div class=\"form-group\">" +
				"   <div class=\"col-sm-8\">\n" +
				"       <input  type=\"text\" value=\"\" readonly lay-verify=\"date\" onblur=\"addTimeBtnData()\"    placeholder=\"年-月-日\" autocomplete=\"off\" class=\"layui-input form-control date_picker danyan\">\n" +
				"</div>\n" +
				"    <div class=\"col-sm-1 addTime\">\n" +
				"        <input type=\"button\" class=\"btn btn-sm btn-danger removeTimeBtn\"  value=\"删除时限\">\n" +
				"    </div>"
		"</div>"
		$(e).parent().parent().parent().append(html);
	}

	function addTimeBtnData(){
		setTimeout(function(){
			var value = [];
			$(".danyan").each(function() {
				value.push($(this).val());
			});
			$('#cell4Id').attr('value',value.join(","))
		},200)
	}
</script>



